import java.util.ArrayList;
import java.util.List;

public class GenerateOOM {
    static final int SIZE = 2 * 1024 * 1024;  //2M

    public static void main(String[] args) throws InterruptedException {
        List<Object> list = new ArrayList<>();
        while (true) {
            list.add(new Object[SIZE]);
            Thread.sleep(20000);
            System.out.println("内存溢出");
        }
    }
}